package com.qfedu.openplateform.manager.controller;

import com.github.pagehelper.PageInfo;
import com.qfedu.openplateform.manager.entity.AjaxMessage;
import com.qfedu.openplateform.manager.entity.Customer;
import com.qfedu.openplateform.manager.entity.TableData;
import com.qfedu.openplateform.manager.entity.UserToken;
import com.qfedu.openplateform.manager.service.UserTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/sys/token")
public class UserTokenController {

    @Autowired
    private UserTokenService userTokenService;

    @RequestMapping( "/table")
    public TableData table(UserToken userToken, Integer page, Integer limit) {
        PageInfo<UserToken> pageInfo = userTokenService.getUserTokenList(userToken, page, limit);
        return new TableData(pageInfo.getTotal(), pageInfo.getList());
    }

    @RequestMapping( "/add")
    public AjaxMessage add(UserToken userToken) {
        try{
            userTokenService.addUserToken(userToken);
            return new AjaxMessage(true,"添加成功");
        }catch (Exception e) {
            e.printStackTrace();
        }
        return new AjaxMessage(false,"添加失败");
    }


    @RequestMapping( "/update")
    public AjaxMessage update(UserToken userToken) {
        try{
            userTokenService.updateUserToken(userToken);
            return new AjaxMessage(true,"修改成功");
        }catch (Exception e) {
            e.printStackTrace();
        }
        return new AjaxMessage(false,"修改失败");
    }

    @RequestMapping( "/del")
    public AjaxMessage del(Integer[] ids) {
        try{
            userTokenService.deleteUserToken(ids);
            return new AjaxMessage(true,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new AjaxMessage(false,"删除失败");

    }

}
